package cn.minds.capture.dispatch.client;

import cn.minds.capture.dispatch.Connect;
import cn.minds.capture.dispatch.TaskManager;
import cn.minds.capture.dispatch.task.Task;
import cn.minds.capture.dispatch.task.TaskHandler;

public class TaskClient implements TaskManager {

	private Connect connect;
	private TaskHandler taskHandler;

	protected TaskClient(ClientManager clientManager, String host, int port) {
		taskHandler = clientManager.getTaskHandlerFacotry().createTaskHandler(this);
		new Client(this, host, port);
	}

	public void setConnect(Connect connect) {
		this.connect = connect;
	}

	public void sendTask(Task task) {
		connect.sendCommand(task);
	}

	// 从任务节点拿到一个任务
	public void receiveTask(Task task) {
		taskHandler.doTask(task);
	}

	public boolean isConnected() {
		return connect.isConnected();
	}

}
